<template>
  <div class="info">
    <van-tabs type="card" v-model="activeName" @click="handleClick">
      <van-tab title="文献资料" name="news">
        <div class="news">
          <van-list
            v-model="loading"
            :finished="finished"
            :offset="0"
            finished-text="没有更多了"
            @load="onLoad">
            <div class="list-box" v-for="(val, index) in newsList" :key="index" @click="toNewsDetails2(val)">
              <p class="van-multi-ellipsis--l2 tit">{{ val.title }}</p>
              <van-row class="desc">
                <van-col span="12">
                  <div class="date">{{ val.createTime }}</div>
                </van-col>
                <van-col span="12">
                </van-col>
              </van-row>
            </div>
          </van-list>
        </div>
      </van-tab>
      <van-tab title="评审意见" name="gg">
        <div class="news">
          <van-list
            v-model="loading2"
            :finished="finished2"
            finished-text="没有更多了"
            :offset="0"
            @load="onLoad2">
            <div class="list-box" v-for="(val, index) in feedList" :key="index" @click="toNewsDetails(val)">
              <p class="van-multi-ellipsis--l2 tit">{{ val.title }}</p>
              <van-row class="desc">
                <van-col span="12">
                  <div class="date">{{ val.createTime }}</div>
                </van-col>
                <van-col span="12">
                </van-col>
              </van-row>
            </div>
          </van-list>
        </div>
      </van-tab>
      <van-tab title="总结报告" name="rl">
        <div class="news">
          <van-list
            v-model="loading3"
            :finished="finished3"
            :offset="0"
            finished-text="没有更多了"
            @load="onLoad3">
            <div class="list-box" v-for="(val, index) in rlList" :key="index" @click="toNewsDetails(val)">
              <p class="van-multi-ellipsis--l2 tit">{{ val.title }}</p>
              <van-row class="desc">
                <van-col span="12">
                  <div class="date">{{ val.createTime }}</div>
                </van-col>
                <van-col span="12">
                </van-col>
              </van-row>
            </div>
          </van-list>
        </div>
      </van-tab>
    </van-tabs>
    <my-footer></my-footer>
  </div>
</template>

<script>
import myFooter from '@/components/Footer'
import { getReviewFeedList, getDocumentationList } from '@/api/home'
export default {
  name: "info",
  data () {
    return {
      feedForm: {
        type: 1,
        userId: '',
        pageNo: 1,
        pageSize: 10
      },
      newsForm: {
        userId: '',
        pageNo: 1,
        pageSize: 10
      },
      rlForm: {
        type: 2,
        userId: '',
        pageNo: 1,
        pageSize: 10
      },
      activeName: 'news',
      total1: 0,
      total2: 0,
      total3: 0,
      feedList: [],
      newsList: [],
      rlList: [],
      loading: false,
      finished: false,
      loading2: false,
      finished2: false,
      loading3: false,
      finished3: false
    }
  },
  components: {
    myFooter
  },
  mounted () {
    this.getNewsList()
  },
  methods: {
    async getNewsList () {
      this.newsForm.userId = this.$store.state.user.userId
      let {data} = await getDocumentationList(this.newsForm)
      if (data.result == 'suc') {
        this.newsList = data.data.result
        this.total1 = data.data.totalCount
      }
    },
    async getFeedList () {
      this.feedForm.userId = this.$store.state.user.userId
      let {data} = await getReviewFeedList(this.feedForm)
      if (data.result == 'suc') {
        this.feedList = data.data.result
        this.total2 = data.data.totalCount
      }
    },
    async getRlList () {
      this.rlForm.userId = this.$store.state.user.userId
      let {data} = await getReviewFeedList(this.rlForm)
      if (data.result == 'suc') {
        this.rlList = data.data.result
        this.total3 = data.data.totalCount
      }
    },
    async onLoad () {
      this.newsForm.userId = this.$store.state.user.userId
      let obj = Object.assign({}, this.newsForm)
      obj.pageNo += 1
      this.loading = true
      let {data} = await getDocumentationList(obj)
      this.loading = false
      if (data.result == 'suc') {
        data.data.result.forEach(item => {
          this.newsList.push(item)
        })
        this.total1 = data.data.totalCount  
      }
      if (this.newsList.length >= this.total1) {
        this.finished = true
      }
    },
    async onLoad2 () {
      this.feedForm.userId = this.$store.state.user.userId
      let obj = Object.assign({}, this.feedForm)
      obj.pageNo += 1
      this.loading2 = true
      let {data} = await getReviewFeedList(obj)
      this.loading2 = false
      if (data.result == 'suc') {
        data.data.result.forEach(item => {
          this.feedList.push(item)
        })
        this.total2 = data.data.totalCount  
      }
      if (this.feedList.length >= this.total2) {
        this.finished2 = true
      }
    },
    async onLoad3 () {
      this.rlForm.userId = this.$store.state.user.userId
      let obj = Object.assign({}, this.rlForm)
      obj.pageNo += 1
      this.loading3 = true
      let {data} = await getReviewFeedList(obj)
      this.loading3 = false
      if (data.result == 'suc') {
        data.data.result.forEach(item => {
          this.rlList.push(item)
        })
        this.total3 = data.data.totalCount  
      }
      if (this.rlList.length >= this.total3) {
        this.finished3 = true
      }
    },
    handleClick(name, title) {
      if(name == 'news') {
        this.getNewsList()
      } else if (name == 'gg') {
        this.getFeedList()
      } else {
        this.getRlList()
      }
    },
    toNewsDetails (row) {
      if (row.type == '1') {
        this.$router.push({path: '/psyjDetails', query: {id: row.id}})
      } else if (row.type == '2') {
        this.$router.push({path: '/ndzjDetails', query: {id: row.id}})
      }
    },
    toNewsDetails2 (row) {
      this.$router.push({path: '/wxDetails', query: {id: row.id}})
    }
  }
}
</script>

<style lang="less">
@import '~@/assets/css/index.less';
.news {
  padding: 0 10% 70px;
  .list-box {
    height: 87px;
    border-radius: 8px;
    border-right: 3px solid #3fb16d;
    box-shadow: 0 3px 15px #d1d1d1;
    &+.list-box {
      margin-top: 20px;
    }
    .news-img {
      height: 61px;
      width: 70px;
      float: right;
      margin: 13px 10px 0 0;
      background-size: cover;
      background-position: 50%;
      border-radius: 4px;
    }
    .tit {
      color: #6a6a6a;
      font-size: @small-size;
      font-weight: 600;
      padding: 16px 16px 0 16px;
      margin: 0;
    }
    .desc {
      margin-top: 12px;
      padding: 0 16px;
      .date {
        color: #a0a3a3;
        font-size: @small-size;
        font-weight: 400;
      }
      .noread {
        color: #a0a3a3;
        font-size: @small-size;
        font-weight: 400;
        text-align: right;
      }
      .read {
        color: #fda233;
        font-size: @small-size;
        font-weight: 400;
        text-align: right;
      }
    }
  }
}
</style>